package com.xydtech.ecard.statistics.service.impl;

import com.xydtech.common.core.text.Convert;
import com.xydtech.ecard.statistics.domain.EcardDeptChecking;
import com.xydtech.ecard.statistics.mapper.EcardDeptCheckingMapper;
import com.xydtech.ecard.statistics.service.IEcardDeptCheckingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 机构考勤统计Service业务层处理
 *
 * @author JHON
 * @date 2022-08-03
 */
@Service
public class EcardDeptCheckingServiceImpl implements IEcardDeptCheckingService {
    @Autowired
    private EcardDeptCheckingMapper ecardDeptCheckingMapper;

    /**
     * 查询机构考勤统计
     *
     * @param deptId 机构考勤统计主键
     * @return 机构考勤统计
     */
    @Override
    public EcardDeptChecking selectEcardDeptCheckingByDeptId(Long deptId) {
        return ecardDeptCheckingMapper.selectEcardDeptCheckingByDeptId(deptId);
    }

    /**
     * 查询机构考勤统计列表
     *
     * @param ecardDeptChecking 机构考勤统计
     * @return 机构考勤统计
     */
    @Override
    public List<EcardDeptChecking> selectEcardDeptCheckingList(EcardDeptChecking ecardDeptChecking) {
        List<EcardDeptChecking> list = ecardDeptCheckingMapper.selectEcardDeptCheckingList(ecardDeptChecking);
        List<EcardDeptChecking> checkingList = new ArrayList<>();
        for (EcardDeptChecking checking : list) {
            ecardDeptChecking.setDeptId(checking.getDeptId());
            List<EcardDeptChecking> infoList = ecardDeptCheckingMapper.selectEcardDeptCheckingInfo(ecardDeptChecking);
            String checkInfo = "";
            for (EcardDeptChecking info : infoList) {
                checkInfo += info.getDeptName() + "：累计打卡次数 " + info.getSumNums() + "。\n";
            }
            checking.setCheckInfo(checkInfo);
            checkingList.add(checking);
        }


        return checkingList;
    }

    /**
     * 新增机构考勤统计
     *
     * @param ecardDeptChecking 机构考勤统计
     * @return 结果
     */
    @Override
    public int insertEcardDeptChecking(EcardDeptChecking ecardDeptChecking) {
        return ecardDeptCheckingMapper.insertEcardDeptChecking(ecardDeptChecking);
    }

    /**
     * 修改机构考勤统计
     *
     * @param ecardDeptChecking 机构考勤统计
     * @return 结果
     */
    @Override
    public int updateEcardDeptChecking(EcardDeptChecking ecardDeptChecking) {
        return ecardDeptCheckingMapper.updateEcardDeptChecking(ecardDeptChecking);
    }

    /**
     * 批量删除机构考勤统计
     *
     * @param deptIds 需要删除的机构考勤统计主键
     * @return 结果
     */
    @Override
    public int deleteEcardDeptCheckingByDeptIds(String deptIds) {
        return ecardDeptCheckingMapper.deleteEcardDeptCheckingByDeptIds(Convert.toStrArray(deptIds));
    }

    /**
     * 删除机构考勤统计信息
     *
     * @param deptId 机构考勤统计主键
     * @return 结果
     */
    @Override
    public int deleteEcardDeptCheckingByDeptId(Long deptId) {
        return ecardDeptCheckingMapper.deleteEcardDeptCheckingByDeptId(deptId);
    }
}
